#include "Melon.h"

CMelon::CMelon(void)
{

}

CMelon::~CMelon(void)
{
}

void CMelon::Init(int worldX, int worldY, CPlayer* playerPtr, Tiles* tilesPtr)
{
	height = 55;
	width = 47;

	health = 100;

	x = (worldX * 32)-(width%32)/2;
	y = (worldY * 32)-(height%32);

	tiles= tilesPtr;

	char picfile[] = "res/Melon.bmp";
	hImage = LoadImage(NULL, picfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

	char picfile2[] = "res/MelonFlip.bmp";
	flipped = LoadImage(NULL, picfile2, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);


	player = playerPtr;
	cooldownTimer = 140;
	cooldown = 140;
	direction = false;
}

void CMelon::Update(){
	//cooldown means the time between the shots of the seeds
	cooldown--;
	
	if(cooldown <= 0){
		cooldown = cooldownTimer;
		if(direction == false){
			bullets->NewBullet(x, y + 30, -3, 0, player,shots, true);
			shots++;
		}
		else{

			bullets->NewBullet(x+50, y + 30, +3, 0, player,shots, true);
			shots++;
		}

		int xDif = player->x - x;
		int yDif = player->y - y;
		if(yDif < 0){
			yDif *=-1;
		}
		if(xDif < 0){
			xDif *= -1;
		}
		if(xDif < 400 && yDif < 300){
			CSoundPlayer::PlaySound1("music\\seed3.wav");
		}
	}
}

void CMelon::Draw(HDC graphics)
{
	if(!direction){
	RenderHelper::RenderBitmap(graphics, hImage, x,y, width, height);
	}
	else{
	RenderHelper::RenderBitmap(graphics, flipped, x,y, width, height);
	}
}